//! ```
//! extern crate align;
//! use align::AlignedMut;
//! use core::{
//!     borrow::{Borrow, BorrowMut},
//!     marker::PhantomData,
//!     mem::{align_of, size_of},
//!     convert::TryInto,
//!     slice,
//! };
//! #[derive(Debug, PartialEq)]
//! struct Test {
//!     t1: u16,
//! }
//! impl Borrow<[u8; size_of::<Self>()]> for Test {
//!     fn borrow(&self) -> &[u8; size_of::<Self>()] {
//!         unsafe {
//!             slice::from_raw_parts(self as *const Self as *const u8, size_of::<Self>())
//!                 .try_into()
//!                 .unwrap()
//!         }
//!     }
//! }
//! impl BorrowMut<[u8; size_of::<Self>()]> for Test {
//!     fn borrow_mut(&mut self) -> &mut [u8; size_of::<Self>()] {
//!         unsafe {
//!             slice::from_raw_parts_mut(self as *mut Self as *mut u8, size_of::<Self>())
//!                 .try_into()
//!                 .unwrap()
//!         }
//!     }
//! }
//! let mut var = [1u8, 2u8];
//! let mut aligned = AlignedMut::<Test>::new(&mut var).unwrap();
//! let var1 = aligned.as_mut();
//! assert_eq!(var1, &Test{t1:0x0201});
//! var1.t1 = 2;
//! assert_eq!(var1, &Test{t1:0x2});
//! assert_eq!(var, [0x02, 0x0]);
//! ```
#![no_std]
#![feature(core_intrinsics)]
// #![allow(incomplete_features)]
// #![feature(const_generics)]
// #![feature(const_evaluatable_checked)]
mod aligned_addr;
mod aligned_slice;

pub use aligned_addr::AlignedAddr;
pub use aligned_slice::AlignedRef;
pub use aligned_slice::AlignedSlice;
pub use aligned_slice::AlignedSliceMut;

#[derive(Debug)]
pub struct MissAlignedError();

pub const ALIGN4KB_ADDR: u32 = 12;
pub const ALIGN32B_ADDR: u32 = 5;

/// 4KB 对齐，意味着最低 12 位为 0；
///
/// 类型参数 T 指代用于存储实际地址的整型，如 usize, u64, u32;
pub type AlignedAddr4KB<T> = AlignedAddr<T, ALIGN4KB_ADDR>;
pub type AlignedAddr32B<T> = AlignedAddr<T, ALIGN32B_ADDR>;
